import { _decorator, Component, EPhysics2DDrawFlags, Label, Node, PhysicsSystem2D, Scheduler, tween, v3 } from 'cc';
import { UIBase } from '../../FrameWork3.8.6/FrameWork/UIFramework/UIBase';
import { ModuleMgr } from '../../FrameWork3.8.6/FrameWork/Module/ModuleMgr';
import { ModuleBase } from '../../FrameWork3.8.6/FrameWork/Module/ModuleBase';
import { GameManager } from '../Game/Manager/GameManager';
const { ccclass, property } = _decorator;

@ccclass('GameUI')
export class GameUI extends UIBase {
    //初始化添加所有的模块
    onLoad(): void {
        this.addAllModule();
        //统一管理模块的初始化生命周期
        ModuleMgr.instance.onInitModule();  
    }
    
    protected start(): void {
        ModuleMgr.instance.onLateInitModule();
    }

    protected update(dt: number): void {
        if(GameManager.instance.timePause){
            return;
        }
        ModuleMgr.instance.onUpdateModule(dt)
    }

    protected lateUpdate(dt: number): void {
        if(GameManager.instance.timePause){
            return;
        }
        ModuleMgr.instance.onLateUpdateModule(dt);
    }



    //添加所有模块的方法
    addAllModule(){
        for(let child of this.node.children){
            let module=child.getComponent(ModuleBase);
            if(!module){
                continue;
            }
            ModuleMgr.instance.addModule(child.name,module);
        }
        
    }
}


